#include<iostream>
#include<map>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int n;
int a[N], l[N], r[N];
int main()
{
	while (cin >> n) {
		if (!n)break;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
			l[i] = i, r[i] = i;
		}
		for (int i = 1; i <= n; i++) {
			while (l[i] - 1 >= 1 && a[l[i] - 1] >= a[i]) l[i] = l[l[i] - 1];
		}
		for (int i = n; i >= 1; i--) {
			while (r[i] + 1 <= n && a[r[i] + 1] <= a[i])r[i] = r[r[i] + 1];
		}
		LL ans = 0;
		for (int i = 1; i <= n; i++) {
			ans = max(ans, 1ll * (r[i] - l[i] + 1) * a[i]);
		}
		cout << ans << endl;
	}
	return 0;
}
